package com.ly.controller;

import com.ly.constant.ResultCodeConstant;
import com.ly.pojo.domain.ProductDO;
import com.ly.pojo.dto.CreateGroup;
import com.ly.pojo.dto.DeleteGroup;
import com.ly.pojo.dto.ProductDTO;
import com.ly.pojo.dto.RestResult;
import com.ly.pojo.dto.UpdateGroup;
import com.ly.pojo.query.ProductQuery;
import com.ly.pojo.query.QueryGroup;
import com.ly.service.ProductsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.lang.Boolean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 产品管理模块
 *
 * @author Administrator
 * @date 2025-03-07 10:51:13
 */
@Tag(name = "产品管理模块")
@RequestMapping("products")
@RestController
public class ProductsController {

    @Autowired
    private ProductsService productsService;

    /**
     * 新增产品
     *
     * @param productDTO 产品信息封装
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @Operation(summary = "新增产品")
    @ResponseBody
    public RestResult<Boolean> addProduct(@RequestBody @Validated(CreateGroup.class) ProductDTO productDTO) {
        Boolean result = productsService.addProduct(productDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 编辑产品
     *
     * @param productDTO 产品信息封装
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @Operation(summary = "编辑产品")
    @ResponseBody
    public RestResult<Boolean> updateProduct(@RequestBody @Validated(UpdateGroup.class) ProductDTO productDTO) {
        Boolean result = productsService.updateProduct(productDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 删除产品
     *
     * @param productQuery 产品查询封装
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @Operation(summary = "删除产品")
    @ResponseBody
    public RestResult<Boolean> deleteProduct(@RequestBody @Validated(DeleteGroup.class) ProductQuery productQuery) {
        Boolean result = productsService.deleteProduct(productQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 获取产品详情
     *
     * @param productQuery 产品查询封装
     * @return
     */
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    @Operation(summary = "获取产品详情")
    public RestResult<ProductDO> getProductInfo(@Validated(QueryGroup.class) ProductQuery productQuery) {
        ProductDO result = productsService.getProductInfo(productQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }
}
